from marshmallow_sqlalchemy import SQLAlchemySchema
from marshmallow import fields
from api.database import db
from api.apps.users.models import User


class UserSchema(SQLAlchemySchema):
    class Meta(SQLAlchemySchema.Meta):
        model = User
        sqla_session = db.session
        load_instance = True  # 允许将数据加载为模型实例

    id = fields.Integer(dump_only=True)
    username = fields.String(required=True)
    password = fields.String(required=True, load_only=True)  # 仅用于反序列化
